<template>
  <el-container class="main_con">
    <div class="filter_con ds_block">
      <div class="button_area"><el-button v-has size="medium" type="primary" @click="adduser">新增企业</el-button></div>
      <!--  <div class="filter_area">
        <el-input size="medium" v-model="params.name" class="serach_input mr_15 mt_15" placeholder="管理员姓名"></el-input>
        <el-input size="medium" v-model="params.mobile" class="serach_input mr_15 mt_15" placeholder="手机号码"></el-input>
        <date-picker size="medium" @change="gettime" class="mr_15 mt_15"></date-picker>
        <el-button size="medium" @click="search">搜索</el-button>
      </div> -->
    </div>
    <div class="list_con">
      <el-table @selection-change="SelectHadnle" :data="list" element-loading-text fit highlight-current-row class="main-loading">
        <el-table-column prop="name" label="企业名称"></el-table-column>

        <el-table-column prop="create_time" label="创建时间"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button v-has type="text" @click='customreHandle(scope.row.id)'>客服账号</el-button>
            <el-button v-has type="text" @click="EditHandle(scope.row.id)">编辑</el-button>
            <el-button v-has type="text" @click="handleClose(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="table_footer">
        <!--  <el-button size="medium">批量删除
        </el-button>-->
        <el-pagination
          @current-change="ChangeCurrent"
          class="pages"
          background
          layout="prev, pager, next"
          :total="total"
          :page-size="size"
          :page-count="page"
          hide-on-single-page
        ></el-pagination>
      </div>
    </div>
    <!-- <el-drawer class="w_80" title="编辑管理员" :visible.sync="drawer" :direction="direction">
      <edituser @on-close="beClose" :uid='user_id' :user_type="user_type"></edituser>
    </el-drawer>-->
    <el-dialog :title="user_type == 'add' ? '新增企业' : '编辑企业'" :visible.sync="drawer" destroy-on-close width="500px">
      <Editcustomer @on-close="beClose" :uid="user_id" :user_type="user_type"></Editcustomer>
    </el-dialog>
    <el-dialog :visible.sync="drawer1"><customerlist :uid="user_id"></customerlist></el-dialog>
  </el-container>
</template>

<script>
import {mapGetters} from 'vuex';
import {getuserlist, deladminuser, editadminuser} from '@/api/mall/admin';
import {getwxcompany,deladwxcompany} from '@/api/mall/customer';
import Editcustomer from './components/Editcustomer';
import customerlist from './components/customerlist';
import DatePicker from '@/components/DatePicker/index';
import {fitter_keyword} from '@/utils/index';
export default {
  data() {
    return {
      params: {
        name: '',
        mobile: '',
        begin_date: '',
        end_date: ''
      },
      paramsdf: {},
      page: 1,
      size: 10,
      total: 0,
      listLoading: true,
      list: [],
      drawer: false,
      drawer1: false,
      direction: 'rtl',
      user_id: '',
      user_type: 'add',
      selectionData: []
    };
  },
  components: {
    Editcustomer,
    customerlist,
    DatePicker
  },

  mounted() {
    this.getlist();
  },
  filters: {
    filter_role(s, list) {
      var d = list.filter(a => {
        return a.id == s;
      });
      if (d.length > 0) {
        return d[0].name;
      } else {
        return '没有该角色';
      }
    }
  },
  methods: {
    search() {
      this.paramsdf = fitter_keyword(this.params);
      this.getlist();
    },
    //启用，禁用
    EnableHandle(data) {
      let _this = this;
      let status = Number(data.status != 1);
      this.$confirm(status ? '确认启用？' : '确认禁用？')
        .then(_ => {
          let params = data;
          params.status = status;
          editadminuser(params).then(res => {
            _this.getlist();
          });
        })
        .catch(_ => {});
    },

    //选择
    SelectHadnle(selection) {
      this.selectionData = selection;
    },
    //删除
    handleClose(id) {
      let _this = this;
      this.$confirm('确认删除？')
        .then(_ => {
          let data = {
            id: id
          };
          deladwxcompany(data).then(res => {
            _this.getlist();
          });
        })
        .catch(_ => {});
    },
    //新增
    adduser() {
      this.user_type = 'add';
      this.drawer = true;
      this.user_id = -1;
    },
    //编辑
    EditHandle(id) {
      this.user_id = id;
      this.user_type = 'edit';
      this.drawer = true;
    },
    customreHandle(id){
      this.user_id = id;
      console.log(1)
      this.drawer1 = true;
    },
    //编辑完成
    beClose() {
      (this.drawer = false), this.getlist();
    },
    //获取列表
    getlist() {
      let data = {
        page: this.page
      };
      getwxcompany(data).then(res => {
        var jsondata = res.msg;
        this.list = jsondata.data;
        this.total = jsondata.total;
        // this.list = response.data.items
        this.listLoading = false;
      });
    },
    //获取时间
    gettime(value) {
      this.params.begin_date = value[0];
      this.params.end_date = value[1];
    },
    //切换页码
    ChangeCurrent(page) {
      this.page = page;
      this.getlist();
    }
  }
};
</script>

<style lang="scss" scoped></style>
